Skip to content

fix(demo): move to a free port and stop cleanly on Ctrl-C - #23

Open
tela wants to merge 1 commit into
mainfrom
feat/demo-robust-serve
Open

tela wants to merge 1 commit into
mainfrom
feat/demo-robust-serve

Conversation

@tela

@tela tela commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Motivation

On a laptop the demo is started and stopped many times. A leftover run on :8080 made the next start fail, and state was kept in ~/Library/Caches, which macOS may clear.

Changes

  • serve without --addr takes the first free port from 8080 to 8089 and prints the URL. An explicit --addr that is taken still fails.
  • serve shuts down on Ctrl-C or SIGTERM and exits 0.
  • Default state moves to the user config dir (~/Library/Application Support on macOS). Existing cache-folder state is not migrated; Reset rebuilds it.
  • docs/troubleshooting.md row for the busy port updated.

This demo starts no child processes, so there is nothing to clean up beyond the server itself.

Tests

  • make test vet: pass. go test -race ./internal/cli: pass.
  • New tests: fallback only when the address was not chosen, serve stops cleanly on cancel, default state is not in a cache folder.
  • Ran the built binary while another demo held :8080: it served on :8081, and exited 0 on SIGTERM.

Related

Independent of localstack-samples/localstack-app-emulators PR #22 (doctor). Both touch internal/cli/cli.go in different places.

A stale run on :8080 stopped the next one, and a kill left the port busy for a moment. State also sat in a cache folder the OS may clear; it now lives in the user config dir.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant